package com.ta;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @ClassName PeriodicTactics
 * @Description 循环策略
 * @Author xiezhuocai
 * @Date 2023/1/31 19:17
 **/
public class PeriodicTactics implements Tactics {

    private final AtomicBoolean atomicBoolean;

    public PeriodicTactics(boolean init){
        this.atomicBoolean = new AtomicBoolean(init);
    }

    public PeriodicTactics(){
        this.atomicBoolean = new AtomicBoolean(true);
    }

    @Override
    public boolean out() {
        boolean b;
        do {
            b = atomicBoolean.get();
        } while (!atomicBoolean.compareAndSet(b, !b));
        return b;
    }
}
